<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Repositories\MenuRepository;
use App\Services\PHPTree;
use App\Repositories\UserRepository;
use App\Repositories\DepartmentRepository;
use App\Repositories\OrderRepository;

class HomeController extends AdminController
{
	public function __construct(MenuRepository $menu, UserRepository $user, DepartmentRepository $department, OrderRepository $order)
	{
		$this->menu = $menu;
        $this->user = $user;
        $this->department = $department;
        $this->order = $order;
	}

    //后台首页
    public function index(Request $request)
    {
        $user = $request->user();

        $departments = (new PHPTree($this->department->all()))->render();
        $managers = $this->user->all()->keyBy('id');

        // v($managers->toArray());

        $regionCount = $this->user->getCountByRegionLists();
        $departmentCount = $this->user->getCountByDepartmentLists();

        // 订单
        $ordercount = $this->order->getCountByStatusLists();

    	return view('admin.index', compact('user', 'request', 'departments', 'managers', 'regionCount', 'departmentCount', 'ordercount'));
    }
}
